<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    [v-cloak] {
        display: none;
    }

    .son {
        font-size: 20px;
        color: red
    }
</style>

<body>
<div id="app" v-cloak>
    {{ total }}
    <button @click="consumer">爸爸挣钱</button>
    <!-- 原生写法 -->
    <!--<son-com :money="total" @update:money="total=$event"></son-com>-->
    <!-- 简写 -->
    <son-com :money.sync="total" class="son"></son-com>
</div>
</body>

<template id="son-cpn">
    <div>
        {{ money }}
        <!-- 我要用100 -->
        <button @click="buyCar">
            <span>儿子花钱</span>
        </button>
    </div>
</template>

<script src="../js/http_cdn.bootcdn.net_ajax_libs_vue_2.6.6_vue.js"></script>
<script>
    const sonComponent = {
        template: '#son-cpn',
        props: ["money"],
        methods: {
            buyCar() {
                this.$emit('update:money', this.money - 100)
            }
        },
    }

    new Vue({
        el: "#app",
        components: {
            'son-com': sonComponent
        },
        data: {
            total: 10000
        },
        methods: {
            consumer() {
                this.total += 100;
            }
        },
    })


</script>

</html>
